package com.briup.shopadmin.web.controller;

import com.briup.shopadmin.common.Result;
import com.briup.shopadmin.common.bean.Order;
import com.briup.shopadmin.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "订单管理相关接口")
@RequestMapping("order")
public class OrderController {
    @Autowired
    IOrderService orderService;

    @GetMapping("getOrderInfo")
    @ApiOperation("订单信息筛选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单编号", defaultValue = ""),
            @ApiImplicitParam(name = "status", value = "订单状态 :\n" +
                    "* 1. 未支付\n" +
                    "* 2. 已支付 待发货 " +
                    "* 3. 已发货 待签收 " +
                    "* 4. 已完成\n" +
                    "* 5. 已关闭", defaultValue = "", allowableValues = "1,2,3,4,5"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示数据条数", required = true),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true)
    })
    public Result getOrderInfo(@RequestParam(required = false, defaultValue = "") String orderId, @RequestParam(required = false, defaultValue = "") String status, Integer pageSize, Integer pageNum) {
        Page<Order> page = orderService.getOrderInfo(orderId, status, pageSize, pageNum);
        return Result.success(page);
    }

    @PostMapping("updateOrder")
    @ApiOperation("订单修改")
    public Result updateOrder(@RequestBody Order order){
        orderService.update(order);
        return  Result.success();
    }

    @GetMapping("getOrder/{id}")
    @ApiOperation("查询订单详情")
    @ApiImplicitParam(name = "id",value = "订单编号")
    public  Result  getOrder(@PathVariable String id){
        Order order = orderService.getOrder(id);
        return  Result.success(order);

    }
}
